# Maintainer: Maxime Gauduin <alucryd@archlinux.org>

pkgname=klipper
pkgver=0.11.0
pkgrel=2
pkgdesc='3D printer firmware with motion planning on the host'
arch=(any)
url=https://www.klipper3d.org/
license=(GPL3)
depends=(
  python-cffi
  python-pyserial
  python-greenlet
  python-jinja
  python-can
  libusb
)
optdepends=(
  'ncurses: for choosing compilation config'
  'avrdude: for flashing firmware on AVR MCU'
  'stm32flash: for flashing firmware on STM MCU'
  'avr-gcc: for AVR MCU firmware compilation'
  'avr-binutils: for AVR MCU firmware compilation'
  'avr-libc: for AVR MCU firmware compilation'
  'python-numpy: for resonance measurement'
  'python-matplotlib: for resonance measurement'
  'dfu-util: for flashing firmware on STM32 MCUs'
)
makedepends=(git)
provides=(klipper)
conflicts=(klipper)
_tag=e02b725602067a2cd098a62be9a4bb10fc74a9bd
source=(
  git+https://github.com/Klipper3d/klipper.git#tag=${_tag}
  klipper.service
  klipper.sysusers
  klipper.tmpfiles
  # data dictionary from https://github.com/Klipper3d/klipper/issues/1438
  klipper-dict.tar.gz::https://github.com/Klipper3d/klipper/files/9992857/klipper-dict-20221111.tar.gz
)
b2sums=('SKIP'
        '6163736c66e8f8711bf004d3b8b3a072269dd1a2959b5b32cd092c904af778c75b280c8dfb0fce44fd20f6b4beb8e95bb96c8daa49658bf654794fa1e77fe8c4'
        '418e30a46010385166a7ca190381c7a9a8d24e36b2663bef3754ad70fa930a91baec4c0f1b1d5c18f5c9ca0045e68b8410f65134c75f504541bc8567350cb9d7'
        'c41b0d0f0d473684aabc55ce76944473e1edf272d05a301f07e2a1978b7d3e7f8bad05e87295eee489163158fb6809b0ce9be62feee7399cc08451825cb85b81'
        '7cbcbbf5815e6449c213db0ac996526244a8d6d9225ce4548d6a8888714aee16414577cfe78ec82884053872f041e8d794b465e005c7c02aca91b1c74cb5d0ba')

pkgver() {
  cd klipper
  git describe --tags | sed 's/^v//'
}

build() {
  cd klipper
  python -m compileall klippy
  python klippy/chelper/__init__.py
}

check() {
  cd klipper
  python scripts/test_klippy.py -d "${srcdir}/dict" -t test/ test/klippy/*.test
}

package() {
  install -dm 755 "${pkgdir}"/opt/klipper
  cp -dr --no-preserve=ownership klipper/{config,docs,klippy,lib,scripts,src,Makefile} "${pkgdir}"/opt/klipper/
  python klipper/scripts/make_version.py arch > "${pkgdir}"/opt/klipper/klippy/.version

  install -Dm 644 klipper.service -t "${pkgdir}"/usr/lib/systemd/system/
  install -Dm 644 klipper.sysusers "${pkgdir}"/usr/lib/sysusers.d/klipper.conf
  install -Dm 644 klipper.tmpfiles "${pkgdir}"/usr/lib/tmpfiles.d/klipper.conf
}

# vim: ts=2 sw=2 et:
